import requests
from config.dxm import *


def page_order_logistics_list_api(state_type, page_no=1, page_size=50):
    """
    分页获取物流追踪条数api
    :param state_type: 物流追踪状态
    :param page_no: 页码
    :param page_size: 每页条数
    :return:
    """
    # 组装防盗链
    headers['referer'] = dxm_config.logisticsTracking['referer']
    return requests.post(
        url=dxm_config.logisticsTracking['url'],
        headers=headers,
        cookies=cookies,
        data={
            "stateType": state_type,
            "pageNo": page_no,
            "pageSize": page_size
        }
    ).text


def get_order_logistics_detail_by_tracking_api(tracking_number='', carrier_code=''):
    """
    获取物流追踪详情
    :param tracking_number: 跟踪号
    :param carrier_code:(物流追踪分页的数据中这个data-carrierCode值)
    :return:
    """
    # 组装防盗链
    headers['referer'] = dxm_config.logisticsTracking['referer']
    return requests.post(
        url=dxm_config.logisticsTracking['details']['url'],
        cookies=cookies,
        headers=headers,
        data={
            "trackingNumber": tracking_number,
            "carrierCode": carrier_code
        }
    ).json()
